package P074_NoUseBinarySearch;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @ClassName : NoUseBinarySearch
 * @Description :不推荐使用BinarySearch对列表进行检索
 * @Author : wukj1
 * @Date: 2022/4/2
 **/
public class NoUseBinarySearch {

    @Test
    public void test(){

        List<String> cities = new ArrayList<>();
        cities.add("上海");
        cities.add("广州");
        cities.add("广州");
        cities.add("北京");
        cities.add("深圳");
        //indexOf获取索引 --原理  遍历查找
        int index1 = cities.indexOf("广州");
        System.out.println("indexOf获取的索引值：" + index1);

        //binarySearch查找索引值 --原理  二分法查找
        int index2 = Collections.binarySearch(cities, "广州");
        System.out.println("binarySearch获取的索引值：" + index2);


    }

}
